<template>
    <!-- 电影详情 start -->
    <div class="detail-box">
        <!-- 电影名称 -->
        <div class="film-name">{{filmDetail.filmName}}</div>
        <!-- 电影信息 stat-->
        <div class="film-info">
            <div class="film-tip">
                <div class="comment-count">
                    <div class="film-source">
                        <span class="star-img open"></span>
                        <span class="star-img open"></span>
                        <span class="star-img open"></span>
                        <span class="star-img close"></span>
                        <span class="star-img close"></span>
                        <span class="star-source">{{filmDetail.source}}</span>
                    </div>
                    <div class="star-count">93601短评</div>
                </div>
                <div class="film-desc">
                    <p>
                        <span>上映时间:</span>{{filmDetail.filmYear}}</p>
                    <p>
                        <span>电影类型:</span>{{filmDetail.filmTypes}}</p>
                    <p>
                        <span>参演明星:</span>{{filmDetail.castNames}}</p>
                </div>
            </div>
            <div class="film-img" :style="`background-image: url(${filmDetail.filmImg})`"></div>
        </div>
        <!-- 电影信息 end-->
        <!-- 电影简介 start -->
        <div class="film-plot">
            <div class="plot-title">剧情简介</div>
            <div class="plot-content">
                {{filmDetail.filmDesc}}
            </div>
        </div>
        <!-- 电影简介 end -->
        <!-- 演员阵容 start -->
        <div class="film-actor">
            <div class="actor-title">导演演员</div>
            <div class="actor-list">
                <div class="actor-item" v-for="(CastNames, index) in getCastNames" :key="index">
                    <div class="actor-img" :style="`background-image: url(${CastNames.photo})`"></div>
                    <div class="actor-name">{{CastNames.name}}</div>
                </div>
            </div>
        </div>
        <!-- 演员阵容 end -->
        <!-- 电影评论 start -->
        <div class="film-comments">
            <div class="comment-title">相关评论</div>
            <comment-item class="comment-list" :filmid="filmDetail.filmId"></comment-item>
        </div>
        <!-- 电影评论 end -->
    </div>
    <!-- 电影详情 end -->
</template>
<script>
    const FilmDetail = Vue.extend({
        template: document.currentScript.ownerDocument.querySelector("template"),
        components: {
            navBar,
            BottomBar,
            CommentItem
        },
        data(){
            return{
                filmDetail:{},
                comments: []
            }
        },
        computed:{
            getCastNames(){
                if(this.filmDetail.castList){
                    return JSON.parse(this.filmDetail.castList);
                }
            }
        },
        methods:{
            getFilmDetailById(id){
                $.ajax({
                    url:"http://localhost/filmApi/loadFilmById.php",
                    data:{
                        filmId:id
                    },
                    dataType:"json",
                    success:({result})=>{
                        // console.log(result);
                        this.filmDetail=result;
                    }
                })
            }
        },
        beforeMount(){
            this.$nextTick(()=>{
                this.getFilmDetailById(this.$root.filmId);
            })
        }
    })
</script>